package com.situ.day11;

import java.lang.String;

// Account:账户
public class AccountAdmin {
    // 余额 (当前账号还有多少钱)
    private Double balance;

    public AccountAdmin(Double balance) {
        this.balance = balance;
    }

    // 存钱
    public void deposit(double money) {
        balance += money;
    }

    // 取钱
    public void withdraw(double money) throws MeiQianException {
        if (balance >= money) {
            balance -= money;
        } else {
            double needMoney = money - balance;
            // 当取钱余额不足的时候，给调用者抛出一个异常，而且这个异常
            // 是编译时异常，需要取钱调用这个方法的人必须要未雨绸缪处理
            throw new MeiQianException(needMoney);
        }
    }

    public static void main(String[] args) {
        AccountAdmin accountAdmin = new AccountAdmin(30000.0);
        accountAdmin.deposit(200);
        try {
            accountAdmin.withdraw(40000.0);
        } catch (MeiQianException e) {
            e.printStackTrace();
        } finally {
            System.out.println("finally");
        }
        System.out.println("AccountAdmin.main");
    }

}
